package com.gz.entity;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


// 实体类
//  自定义数据类型
public class PageCount implements DBWritable, Writable {
    private String siteId;
    private int pv;
    private int uv;
    private int ip;
    private int newUser;
    private String dateTime;
    
    public PageCount(){}
    
    public PageCount(String siteId, int pv, int uv, int ip, int newUser) {
        this.siteId = siteId;
        this.pv = pv;
        this.uv=uv;
        this.ip=ip;
        this.newUser=newUser;
    }
    
    public void write(DataOutput out) throws IOException {
        out.writeUTF(siteId);
        out.writeInt(pv);
        out.writeInt(uv);
        out.writeInt(ip);
        out.writeInt(newUser);
    }
    
    public void readFields(DataInput in) throws IOException {
        siteId=in.readUTF();
        pv=in.readInt();
        uv=in.readInt();
        ip=in.readInt();
        newUser=in.readInt();
    }
    
    //DB写数据的过程
    public void write(PreparedStatement statement)
            throws SQLException {
        
        statement.setString(1, siteId);
        statement.setInt(2, pv);
        statement.setInt(3, uv);
        statement.setInt(4, ip);
        statement.setInt(5, newUser);
        
    }
    
    //DB读数据的过程
    public void readFields(ResultSet resultSet)
            throws SQLException {
        
        siteId=resultSet.getString(1);
        pv=resultSet.getInt(2);
        uv=resultSet.getInt(3);
        ip=resultSet.getInt(4);
        newUser=resultSet.getInt(5);
    }
    
    public String getSiteId() {
        return siteId;
    }
    
    public void setSiteId(String siteId) {
        this.siteId = siteId;
    }
    
    public int getPv() {
        return pv;
    }
    
    public void setPv(int pv) {
        this.pv = pv;
    }
    
    public int getUv() {
        return uv;
    }
    
    public void setUv(int uv) {
        this.uv = uv;
    }
    
    public int getIp() {
        return ip;
    }
    
    public void setIp(int ip) {
        this.ip = ip;
    }
    
    public int getNewUser() {
        return newUser;
    }
    
    public void setNewUser(int newUser) {
        this.newUser = newUser;
    }
    
    public String getDateTime() {
        return dateTime;
    }
    
    public void setDateTime(String dateTime) {
        this.dateTime = dateTime;
    }
}
